#include "comm.hpp"
int main()
{
    Init i;
    
    int shmid = CreateShm();
    char* shmaddr = (char*)shmat(shmid, nullptr, 0);


    int fd = open(FIFO_FILE, O_RDONLY);


    struct shmid_ds shmds;

    //ipc code
    while(true)
    {
        char c;
        ssize_t n = read(fd, &c, 1);
        if(n == 0) break;
        else if(n < 0) break;
        cout << "process assess a message: " << shmaddr << endl;;
        sleep(1);
        shmctl(shmid, IPC_STAT, &shmds);
        cout << "shm size: " << shmds.shm_segsz <<endl;
        cout << "shm nattch: " << shmds.shm_nattch <<endl;
        printf("shm __key: 0x%x \n" ,shmds.shm_perm.__key);
        cout << "shm mode: " << shmds.shm_perm.mode <<endl;

    }



    shmdt(shmaddr);
    shmctl(shmid, IPC_RMID, nullptr);
    close(fd);
    return 0;
}